package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Slf4j
@Api(value = "套餐管理相关接口")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @ApiOperation( "添加新套餐接口")
    @PostMapping("/admin/setmeal")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO) {
        log.info("添加新套餐:{}", setmealDTO);
        setmealService.add(setmealDTO);
        return Result.success();
    }


    @ApiOperation( "套餐分页查询接口")
    @GetMapping("/admin/setmeal/page")
    public Result<PageResult> selectByPage(SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("套餐分页查询参数：{}", setmealPageQueryDTO);
        PageResult pageResult = setmealService.selectByPage(setmealPageQueryDTO);
        return Result.success(pageResult);
    }


    @ApiOperation( "套餐起售停售接口")
    @PostMapping("/admin/setmeal/status/{status}")
    public Result updateStatus(@PathVariable Integer status, Long id) {
        log.info("套餐起售停售接口，参数：{},{}", status, id);
        setmealService.updateStatus(status, id);
        return Result.success();
    }


    //根据id查询套餐
    @ApiOperation( "根据id查询套餐信息接口")
    @GetMapping("/admin/setmeal/{id}")
    public Result<SetmealVO> selectById(@PathVariable Long id) {
        log.info("根据id查询套餐接口，参数：{}", id);
        SetmealVO setmealVO = setmealService.selectById(id);
        return Result.success(setmealVO);
    }


    //更新套餐信息
    @ApiOperation( "更新套餐信息接口")
    @PutMapping("/admin/setmeal")
    public Result update(@RequestBody SetmealDTO setmealDTO) {
        log.info("更新套餐信息接口，参数：{}", setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }

    //删除套餐
    @ApiOperation( "删除套餐接口")
    @DeleteMapping("/admin/setmeal")
    public Result delete(@RequestParam List<Long> ids) {
        log.info("删除套餐接口，参数：{}", ids);
        setmealService.delete(ids);
        return Result.success();
    }
}
